﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing.Imaging;
using System.Drawing;

namespace Extellect.Utilities.Drawing.Imaging
{
    /// <summary>
    /// Collection of colors from a Rainbow palette (similar to some infrared cameras)
    /// </summary>
    public static class Rainbow
    {
        private readonly static Color[] colors = new Color[]
        {
            Color.FromArgb(0,0,0),
            Color.FromArgb(7,2,7),
            Color.FromArgb(15,4,15),
            Color.FromArgb(22,6,22),
            Color.FromArgb(30,8,30),
            Color.FromArgb(37,10,37),
            Color.FromArgb(45,12,45),
            Color.FromArgb(52,14,52),
            Color.FromArgb(60,16,60),
            Color.FromArgb(67,18,67),
            Color.FromArgb(75,20,75),
            Color.FromArgb(82,22,82),
            Color.FromArgb(90,24,90),
            Color.FromArgb(97,26,97),
            Color.FromArgb(105,28,105),
            Color.FromArgb(112,31,112),
            Color.FromArgb(120,33,120),
            Color.FromArgb(128,35,128),
            Color.FromArgb(135,37,135),
            Color.FromArgb(143,39,143),
            Color.FromArgb(150,41,150),
            Color.FromArgb(158,43,158),
            Color.FromArgb(165,45,165),
            Color.FromArgb(173,47,173),
            Color.FromArgb(180,49,180),
            Color.FromArgb(188,51,188),
            Color.FromArgb(195,53,195),
            Color.FromArgb(203,55,203),
            Color.FromArgb(210,57,210),
            Color.FromArgb(218,60,218),
            Color.FromArgb(225,62,225),
            Color.FromArgb(233,64,233),
            Color.FromArgb(239,65,239),
            Color.FromArgb(231,64,237),
            Color.FromArgb(224,63,235),
            Color.FromArgb(216,62,233),
            Color.FromArgb(208,61,231),
            Color.FromArgb(201,60,229),
            Color.FromArgb(193,59,227),
            Color.FromArgb(186,58,225),
            Color.FromArgb(178,57,223),
            Color.FromArgb(171,56,221),
            Color.FromArgb(163,55,219),
            Color.FromArgb(156,54,217),
            Color.FromArgb(148,53,215),
            Color.FromArgb(141,52,213),
            Color.FromArgb(133,51,211),
            Color.FromArgb(126,50,209),
            Color.FromArgb(118,49,207),
            Color.FromArgb(111,48,205),
            Color.FromArgb(103,47,203),
            Color.FromArgb(95,46,201),
            Color.FromArgb(88,45,198),
            Color.FromArgb(80,44,196),
            Color.FromArgb(73,43,194),
            Color.FromArgb(65,42,192),
            Color.FromArgb(58,41,190),
            Color.FromArgb(50,40,188),
            Color.FromArgb(43,39,186),
            Color.FromArgb(35,38,184),
            Color.FromArgb(28,37,182),
            Color.FromArgb(20,36,180),
            Color.FromArgb(13,35,178),
            Color.FromArgb(5,34,176),
            Color.FromArgb(0,35,175),
            Color.FromArgb(0,42,177),
            Color.FromArgb(0,48,179),
            Color.FromArgb(0,55,181),
            Color.FromArgb(0,61,183),
            Color.FromArgb(0,67,185),
            Color.FromArgb(0,74,187),
            Color.FromArgb(0,80,189),
            Color.FromArgb(0,87,191),
            Color.FromArgb(0,93,193),
            Color.FromArgb(0,100,195),
            Color.FromArgb(0,106,197),
            Color.FromArgb(0,113,199),
            Color.FromArgb(0,119,202),
            Color.FromArgb(0,126,204),
            Color.FromArgb(0,132,206),
            Color.FromArgb(0,139,208),
            Color.FromArgb(0,145,210),
            Color.FromArgb(0,151,212),
            Color.FromArgb(0,158,214),
            Color.FromArgb(0,164,216),
            Color.FromArgb(0,171,218),
            Color.FromArgb(0,177,220),
            Color.FromArgb(0,184,222),
            Color.FromArgb(0,190,224),
            Color.FromArgb(0,197,226),
            Color.FromArgb(0,203,228),
            Color.FromArgb(0,210,230),
            Color.FromArgb(0,216,232),
            Color.FromArgb(0,223,234),
            Color.FromArgb(0,229,236),
            Color.FromArgb(0,235,238),
            Color.FromArgb(0,238,237),
            Color.FromArgb(0,233,229),
            Color.FromArgb(0,229,222),
            Color.FromArgb(0,224,214),
            Color.FromArgb(0,220,207),
            Color.FromArgb(0,215,199),
            Color.FromArgb(0,211,191),
            Color.FromArgb(0,206,184),
            Color.FromArgb(0,202,176),
            Color.FromArgb(0,197,169),
            Color.FromArgb(0,193,161),
            Color.FromArgb(0,188,154),
            Color.FromArgb(0,184,146),
            Color.FromArgb(0,179,139),
            Color.FromArgb(0,175,131),
            Color.FromArgb(0,170,124),
            Color.FromArgb(0,166,116),
            Color.FromArgb(0,161,109),
            Color.FromArgb(0,156,101),
            Color.FromArgb(0,152,94),
            Color.FromArgb(0,147,86),
            Color.FromArgb(0,143,79),
            Color.FromArgb(0,138,71),
            Color.FromArgb(0,134,63),
            Color.FromArgb(0,129,56),
            Color.FromArgb(0,125,48),
            Color.FromArgb(0,120,41),
            Color.FromArgb(0,116,33),
            Color.FromArgb(0,111,26),
            Color.FromArgb(0,107,18),
            Color.FromArgb(0,102,11),
            Color.FromArgb(0,98,3),
            Color.FromArgb(3,98,0),
            Color.FromArgb(10,102,0),
            Color.FromArgb(18,107,0),
            Color.FromArgb(25,111,0),
            Color.FromArgb(32,116,0),
            Color.FromArgb(39,120,0),
            Color.FromArgb(47,125,0),
            Color.FromArgb(54,129,0),
            Color.FromArgb(61,134,0),
            Color.FromArgb(68,138,0),
            Color.FromArgb(76,143,0),
            Color.FromArgb(83,147,0),
            Color.FromArgb(90,152,0),
            Color.FromArgb(97,156,0),
            Color.FromArgb(105,161,0),
            Color.FromArgb(112,166,0),
            Color.FromArgb(119,170,0),
            Color.FromArgb(126,175,0),
            Color.FromArgb(134,179,0),
            Color.FromArgb(141,184,0),
            Color.FromArgb(148,188,0),
            Color.FromArgb(155,193,0),
            Color.FromArgb(163,197,0),
            Color.FromArgb(170,202,0),
            Color.FromArgb(177,206,0),
            Color.FromArgb(184,211,0),
            Color.FromArgb(192,215,0),
            Color.FromArgb(199,220,0),
            Color.FromArgb(206,224,0),
            Color.FromArgb(213,229,0),
            Color.FromArgb(221,233,0),
            Color.FromArgb(228,238,0),
            Color.FromArgb(229,235,0),
            Color.FromArgb(226,227,0),
            Color.FromArgb(223,220,0),
            Color.FromArgb(220,212,0),
            Color.FromArgb(217,205,0),
            Color.FromArgb(214,197,0),
            Color.FromArgb(211,190,0),
            Color.FromArgb(208,182,0),
            Color.FromArgb(205,175,0),
            Color.FromArgb(202,167,0),
            Color.FromArgb(200,160,0),
            Color.FromArgb(197,152,0),
            Color.FromArgb(194,144,0),
            Color.FromArgb(191,137,0),
            Color.FromArgb(188,129,0),
            Color.FromArgb(185,122,0),
            Color.FromArgb(182,114,0),
            Color.FromArgb(179,107,0),
            Color.FromArgb(176,99,0),
            Color.FromArgb(173,92,0),
            Color.FromArgb(170,84,0),
            Color.FromArgb(167,77,0),
            Color.FromArgb(164,69,0),
            Color.FromArgb(162,62,0),
            Color.FromArgb(159,54,0),
            Color.FromArgb(156,47,0),
            Color.FromArgb(153,39,0),
            Color.FromArgb(150,32,0),
            Color.FromArgb(147,24,0),
            Color.FromArgb(144,16,0),
            Color.FromArgb(141,9,0),
            Color.FromArgb(138,1,0),
            Color.FromArgb(140,1,1),
            Color.FromArgb(143,4,4),
            Color.FromArgb(146,6,6),
            Color.FromArgb(149,9,9),
            Color.FromArgb(153,12,12),
            Color.FromArgb(156,14,14),
            Color.FromArgb(159,17,17),
            Color.FromArgb(162,19,19),
            Color.FromArgb(166,22,22),
            Color.FromArgb(169,24,24),
            Color.FromArgb(172,27,27),
            Color.FromArgb(175,29,29),
            Color.FromArgb(178,32,32),
            Color.FromArgb(182,34,34),
            Color.FromArgb(185,37,37),
            Color.FromArgb(188,40,40),
            Color.FromArgb(191,42,42),
            Color.FromArgb(194,45,45),
            Color.FromArgb(197,47,47),
            Color.FromArgb(201,50,50),
            Color.FromArgb(204,52,52),
            Color.FromArgb(207,55,55),
            Color.FromArgb(210,57,57),
            Color.FromArgb(214,60,60),
            Color.FromArgb(217,62,62),
            Color.FromArgb(220,65,65),
            Color.FromArgb(223,67,67),
            Color.FromArgb(226,70,70),
            Color.FromArgb(230,73,73),
            Color.FromArgb(233,75,75),
            Color.FromArgb(236,78,78),
            Color.FromArgb(239,80,80),
            Color.FromArgb(240,85,85),
            Color.FromArgb(240,91,91),
            Color.FromArgb(241,96,96),
            Color.FromArgb(241,102,102),
            Color.FromArgb(242,107,107),
            Color.FromArgb(242,113,113),
            Color.FromArgb(243,118,118),
            Color.FromArgb(243,123,123),
            Color.FromArgb(244,129,129),
            Color.FromArgb(244,134,134),
            Color.FromArgb(245,140,140),
            Color.FromArgb(245,145,145),
            Color.FromArgb(246,151,151),
            Color.FromArgb(246,156,156),
            Color.FromArgb(247,162,162),
            Color.FromArgb(247,167,167),
            Color.FromArgb(247,173,173),
            Color.FromArgb(248,178,178),
            Color.FromArgb(248,184,184),
            Color.FromArgb(249,189,189),
            Color.FromArgb(249,194,194),
            Color.FromArgb(250,200,200),
            Color.FromArgb(250,205,205),
            Color.FromArgb(251,211,211),
            Color.FromArgb(251,216,216),
            Color.FromArgb(252,222,222),
            Color.FromArgb(252,227,227),
            Color.FromArgb(253,233,233),
            Color.FromArgb(253,238,238),
            Color.FromArgb(254,244,244),
            Color.FromArgb(254,249,249),
            Color.FromArgb(255,255,255),
        };

        /// <summary>
        /// Loads a color palette with these entries.
        /// </summary>
        public static void Load(ColorPalette colorPalette)
        {
            for (int i = 0; i < colors.Length; i++)
            {
                colorPalette.Entries[i] = colors[i];
            }
        }

        /// <summary>
        /// Gets the color at the specified index
        /// </summary>
        public static Color GetColorAt(byte index)
        {
            return colors[index];
        }
    }
}
